#include "Error.h"
#include <math.h>
#include <cstdlib>
#include <stdio.h>
#include <iostream>
#include <cmath>

Error::Error(Grid* g) {
    grid = g;
    num_r = grid->getNumberR();
    num_z = grid->getNumberZ();
    left_r = grid->getLeftR();
    down_z = grid->getDownZ();
    h_r = grid->getHR();
    h_z = grid->getHZ();
}

float Error::getValue(float** psipl, float** psipl_mnxt){
    float res = 0;
    float t1, t2 = 0;


    for (int j = 0; j < num_z; j++) {

        for (int i = 0; i < num_r; i++) {
            if(psipl[i][j] == 0.)
              { plog->writeErr("error miscal value 0");            }
            else {


            res = res + abs ((psipl_mnxt[i][j] - psipl[i][j])/psipl[i][j]);
           
            }

        }
    }


    if (res != res) {
        plog->writeErr("error miscal value");
    }


    return res;
};

float Error::getValue(Matrix m1, Matrix m2) {
    float sum = 0;
    for (int j = 0; j < m1.ColNo(); j++) {
        for (int i = 0; i < m1.RowNo(); i ++) {


            sum = sum + pow((m1(i,j) - m2(i,j)),2);

        }
    }

    return sqrt(sum);

}
